<script setup>
import SideMenu from '../components/SideMenu.vue'
import { ElMessage } from 'element-plus'
import { useRouter } from 'vue-router'
import { ArrowDown, User, SwitchButton } from '@element-plus/icons-vue'

const router = useRouter()

const handleCommand = (command) => {
  if (command === 'logout') {
    localStorage.removeItem('token')
    ElMessage.success('退出登录成功')
    router.push('/login')
  } else if (command === 'profile') {
    router.push('/profile')
  }
}
</script>

<template>
  <div class="app-container">
    <!-- 顶部标题栏 -->
    <div class="header">
      <div class="title-container">
        <img src="../assets/logo/轩宝阁 - 副本.png" alt="logo" class="header-logo">
        <h1 class="title">后台管理系统</h1>
      </div>
      <div class="header-right">
        <el-dropdown @command="handleCommand" trigger="click">
          <div class="user-info">
            <el-avatar :size="32" src="https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png" />
            <span class="username">张三</span>
            <el-icon class="el-icon--right"><arrow-down /></el-icon>
          </div>
          <template #dropdown>
            <el-dropdown-menu>
              <el-dropdown-item command="profile">
                <el-icon><user /></el-icon>
                个人中心
              </el-dropdown-item>
              <el-dropdown-item divided command="logout">
                <el-icon><switch-button /></el-icon>
                退出登录
              </el-dropdown-item>
            </el-dropdown-menu>
          </template>
        </el-dropdown>
      </div>
    </div>

    <!-- 主要内容区 -->
    <div class="main-container">
      <SideMenu />
      <div class="content">
        <router-view />
      </div>
    </div>
  </div>
</template>

<style scoped>
.app-container {
  min-height: 100vh;
}

.header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 50px;
  background-color: #2c3e50;
  color: #fff;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 20px;
  z-index: 1001;
}

.title-container {
  display: flex;
  align-items: center;
  gap: 15px;
}

.header-logo {
  width: 60px;
  object-fit: contain;
}

.title {
  font-family: "Microsoft YaHei", "微软雅黑", sans-serif;
  font-size: 23px;
  font-weight: 600;
  background: linear-gradient(to right, #ffffff, #e6e6e6);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  letter-spacing: 2px;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  margin: 0;
}

.header-right {
  display: flex;
  align-items: center;
}

.user-info {
  display: flex;
  align-items: center;
  cursor: pointer;
  padding: 0 8px;
  height: 40px;
  border-radius: 4px;
  transition: background-color 0.3s;
}

.user-info:hover {
  background: rgba(255, 255, 255, 0.1);
}

.username {
  margin: 0 8px;
  color: #fff;
  font-size: 14px;
}

:deep(.el-dropdown-menu__item) {
  display: flex;
  align-items: center;
  gap: 8px;
}

:deep(.el-icon) {
  color: #fff;
}

.main-container {
  padding-top: 50px;
  display: flex;
}

.content {
  width: 1460px;
  padding: 20px;
  min-height: calc(100vh - 50px);
  background-color: #f4f6f9;
}
</style> 